package cn.jksoft.businessclient.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.jksoft.businessclient.R;
import cn.jksoft.businessclient.bean.CustCardEntity;
import cn.jksoft.businessclient.utils.DensityUtils;

/**
 * Author:  nick
 * Email:   nickdevp@gmail.com
 * Date:    16/5/11 15:03.
 * Description:
 */
public class CKCardAdapter extends RecyclerView.Adapter<CKCardAdapter.ItemViewHolder> {
    private Context context;
    private LayoutInflater inflater;
    private List<CustCardEntity.CustomerCardListEntity.MemberPackageItemListEntity> dataList;


    public CKCardAdapter(Context context, List<CustCardEntity.CustomerCardListEntity.MemberPackageItemListEntity> list) {
        this.context = context;
        this.dataList = list;
        inflater = LayoutInflater.from(context);
    }

    public void addDataList(List<CustCardEntity.CustomerCardListEntity.MemberPackageItemListEntity> list){
        this.dataList.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public ItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = inflater.inflate(R.layout.item_membership_card_service, viewGroup, false);
        ItemViewHolder itemViewHolder = new ItemViewHolder(view);
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        int width = (windowManager.getDefaultDisplay().getWidth()- DensityUtils.dip2px(context,68))/4;

        LinearLayout.LayoutParams params =  new LinearLayout.LayoutParams(
                width,
                LinearLayout.LayoutParams.WRAP_CONTENT
        );
        itemViewHolder.prodName.setLayoutParams(params);
        itemViewHolder.surplusNumber.setLayoutParams(params);
        return itemViewHolder;
    }

    @Override
    public void onBindViewHolder(final ItemViewHolder itemViewHolder, int i) {
        CustCardEntity.CustomerCardListEntity.MemberPackageItemListEntity dataBean = dataList.get(i);
        itemViewHolder.surplusNumber.setText(dataBean.getSURPLUS_NUMBER()+"");
        itemViewHolder.prodName.setText(dataBean.getPROD_NAME());
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    public static class ItemViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_surplus_number)
        TextView surplusNumber;
        @Bind(R.id.tv_prod_name)
        TextView prodName;

        public ItemViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
